function Category_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="find" class="finds"><input id="keyword" class="bordersolid" type="text" value="" onblur="Show_Search()" onkeyup="Product_Search();"/><div id="searchicon" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons" class="searchicons"><img src="img/jings.jpg"/></div></div>');
	buffer.append('<div class="horizen border-bottom"></div>');
	return buffer.toString();
};

function Category_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="customerlist border-bottom" id="'+info.big.ID+'" parentid="'+info.big.ParentID+'"><div class="customername">'+info.big.Name+'</div><div class="customerinfo"><div class="state"></div><div class="lastconntime"></div></div></div>');
		$(info.small).each(function(i,small){
			buffer.append('<div class="customerlist border-bottom" id="'+small.ID+'" parentid="'+small.ParentID+'"><div class="customername" style="padding-left:40px;">'+small.Name+'</div><div class="customerinfo"><div class="state"></div><div class="lastconntime"></div></div></div>');
		});
	});
	return buffer.toString();
};

function Receive_Category(pageindex)
{
	var data = {};
			data.act = "Find_AllCategory";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword").val();
		    data.timer = "";
		    data.categoryid = 0;
		    data.sign=GetSign(data.act);
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.category.length>0)
				{
					$("#contentlist3").html('<div id="nlist" style="float:left; min-height: '+sheight+'px;"></div>');
					$("#contentlist3").append(Category_Data(json.data.category));
					setTimeout(function(){
						Init_Categorys();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					$("#contentlist3").append('<div class="loading">长按可以删除哦</div>');
					if(json.data.category.length!=data.pagesize)
					{
						$("#loading3").html("");
					}else{
						$("#loading3").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					
					if(pageindex==1)
					{
						$("#contentlist3").html("");
						$("#loading3").html("主人，没有找到您需要的数据"); 
					}
					else
					{
						$("#loading3").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#divmsg3").attr("pageindex"))+1;
         		$("#divmsg3").attr("pageindex",pageindex);
			});
};

function Category_Search(){
	Receive_Category(1);
};

function Init_Categorys()
{
	mui("#contentlist3").off("tap",".customerlist");
	mui("#contentlist3").off("longtap",".customerlist");
	mui("#contentlist3").on("tap",".customerlist",function(){
		obj=$(this);
		OpenWindow(4,"产品分类","保存",function(){
			Save_Category();
		});
		$("#contentlist4").html(CategoryAdd_Code($(this).attr("id"),$(this).attr("parentid"),$(this).find(".customername").html()));
		Init_CategoryAdd();
	});
	mui("#contentlist3").on("longtap",".customerlist",function(){
			obj=$(this);
        	plus.nativeUI.confirm("确定要删除吗？", function(event){
				if(event.index==1)
				{
					var data = {};
				    data.act = "Delete_Category";
				    data.id = obj.attr("id");
				    data.userid=userid;
					data.comid=comid;
					data.source=source;
					data.sign=GetSign(data.act);
				    mui.getJSON(crm_domain, data, function(json) {
				    	plus.nativeUI.toast(json.msg);
						if(json.state)
						{
							obj.hide(300);
						}
				    });	
				}
			},"提示", ["取消","确认"]); 
	});
};
